package edu.qd.learn.newchapter.chapter03.lambda;

import edu.qd.learn.newchapter.chapter03.reflect.demo01.entity.Dog;

import java.util.Arrays;
import java.util.function.*;

/**
 * @author 布衣
 */
public class DemoLambda {

    public static void main(String[] args) {
//        lambda 不能独立存在  跟接口函数 一起存在
        Computed sum = (x, y) -> Math.min(x, y);
        int sum1 = sum.deal(2, 3);
        System.out.println("和" + sum1);

        int[] arrs = new int[]{1, 2, 3, 4, 56};

        //数组stream : 串流  IntConsumer
        Arrays.stream(arrs).forEach((x) -> System.out.println(x));

        System.out.println(Arrays.toString(arrs));

        for (int i = 0; i < arrs.length; i++) {
            System.out.println(arrs[i]);
        }

        for (int t : arrs) {
            System.out.println(t);
        }
        int i = 0;
        while (i < arrs.length) {
            System.out.println(arrs[i++]);
        }

        double[] arrs1 = new double[]{1, 2, 3, 4, 56};
        Arrays.stream(arrs1).forEach(x -> System.out.println(x));

        //创建一个实例
        Supplier<Dog> s = () -> new Dog();
        Dog t = new Dog();
        Dog t1 = s.get();


        int[] arrs2 = new int[]{1, 2, 3, 4, 56};
        print2(arrs2, x -> x >> 1 >= 3);

        Function<Integer, Integer> fn = x -> x + 3;
        Integer apply = fn.apply(4);
        // D F L  0x123(16进制) 0B0101010(二进制) 0123(八进制)

        int a = 0X123;
        int b = 0B11100;
        int c = 076600;


        BiFunction<Double, Integer, Double> fn1 = (x, y) -> x * y;
        Double apply1 = fn1.apply(2d, 9);
        Predicate<Integer> p1 = (x) -> x > 3;
        BiPredicate<Integer, Double> p2 = (x, y) -> x > y;
    }

    public static void print2(int[] arrs2, Predicate<Integer> test) {
        for (int i1 = 0; i1 < arrs2.length; i1++) {
            if (test.test(i1)) {
                System.out.println(i1);
            }
        }
    }


    // 进制 （....）
    // lambda 先看我的，分析四种什么用...代码看了
    // 题: ---
}
